import 'package:collection/collection.dart';
import 'package:lpinyin/lpinyin.dart';


void main() {
  List<AddressItemModel> _list = addressMockData();
  Map<String, List<AddressItemModel>> map = groupBy<AddressItemModel,String>(_list,
          (i) => i.shortPinYin[0].toUpperCase());
  var list = map.keys.toList();
  list.sort((i1,i2) => i1.compareTo(i2));


  list.forEach((k) {
    print(k);
    map[k].sort((i1, i2) => i1.shortPinYin.compareTo(i2.shortPinYin));
    map[k].forEach((m) => print(m.toString()));
    print("-----------");
  });
}

List<AddressItemModel> addressMockData() {
//  return
  return <AddressItemModel>[
    AddressItemModel(name: "江德福"),
    AddressItemModel(name: "校长"),
    AddressItemModel(name: "安杰"),
    AddressItemModel(name: "老丁"),
    AddressItemModel(name: "江德华"),
    AddressItemModel(name: "江亚菲"),
    AddressItemModel(name: "江亚宁"),
    AddressItemModel(name: "江卫国"),
    AddressItemModel(name: "江卫东"),
    AddressItemModel(name: "江卫民"),
    AddressItemModel(name: "王海洋"),
    AddressItemModel(name: "欧阳懿"),
    AddressItemModel(name: "安欣"),
    AddressItemModel(name: "安泰"),
    AddressItemModel(name: "欧阳安然"),
    AddressItemModel(name: "欧阳安诺"),
    AddressItemModel(name: "阿甘"),
    AddressItemModel(name: "许三多"),
    AddressItemModel(name: "李云龙"),
    AddressItemModel(name: "魏和尚"),
    AddressItemModel(name: "赵刚"),
    AddressItemModel(name: "楚云飞"),
    AddressItemModel(name: "李达康"),
    AddressItemModel(name: "侯亮平"),
    AddressItemModel(name: "冷锋"),
    AddressItemModel(name: "托尔"),
    AddressItemModel(name: "巴基"),
  ];
}

class AddressItemModel {
  final String name;
  final String img;
  String shortPinYin;

  AddressItemModel({this.name, this.img = ""})
      : shortPinYin = PinyinHelper.getShortPinyin(name);

  @override
  String toString() {
    return 'AddressItemModel{name: $name, img: $img}';
  }
}